import 'package:cbec_app/components/base/base_chekbox.dart';
import 'package:cbec_app/components/base/base_interactive.dart';
import 'package:cbec_app/components/base/base_page.dart';
import 'package:cbec_app/components/base/base_nav_bar.dart';
import 'package:cbec_app/components/common/common_style.dart';
import 'package:cbec_app/components/common/not_found.dart';
import 'package:cbec_app/components/goods/goods_info_item.dart';
import 'package:cbec_app/pages/my/controller/footprint_ctr.dart';
import 'package:cbec_app/utils/Tools.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

//足迹
class Footprint extends GetView<FootprintController> {
  const Footprint({super.key});

  @override
  Widget build(BuildContext context) {
    return GetBuilder<FootprintController>(builder: (controller) {
      return BasePage(
        title: "我的足迹",
        iconType: IconType.back,
        isShowPadding: true,
        children: [
          Container(
            height: 570.h,
            child: controller.data.isNotEmpty
                ? Tools.getPullRefresh(
                    refreshController: controller.baseRefreshCtr,
                    onLoading: controller.onPageLoading,
                    onRefresh: controller.onPageRefresh,
                    enablePullDown: false,
                    enablePullUp: false,
                    child: ListView.builder(
                        reverse: false,
                        controller: controller.scrollController,
                        itemCount: controller.data.length,
                        itemBuilder: (context, index) {
                          final Map<String, dynamic> sectionData = controller.data[index];
                          List<Map<String, dynamic>> items = List<Map<String, dynamic>>.from(sectionData['list']);
                          return Column(
                            children: [
                              Container(
                                  margin: EdgeInsets.only(top: 14.w),
                                  child: Row(
                                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                    children: [
                                      Text(sectionData['date'], style: setTextStyle(15, FontWeight.w500, Tools.fromHex("#333333"))),
                                      /*
                              index==0? BaseInteractive(
                                  onClick: () => {
                                    controller.edit()},
                                  childWidget: Text(controller.actionTxt,
                                      style: setTextStyle(15, FontWeight.w500,
                                          Tools.fromHex("#333333"))),
                                ):const SizedBox()

                               */
                                    ],
                                  )),
                              for (var item in items)
                                GoodsInfoItem(
                                  isShowCheckBox: controller.showButton,
                                  infoStyle: InfoStyle.collect,
                                  btnType: RightBtnType.car,
                                  margin: EdgeInsets.only(top: 10.w),
                                  goodsInfo: {"goodsId": item["goodsId"], "mainImage": item['imgUrl'], "commodityName": item['goodsName'], "price": item["price"], "priceMarket": "100", "isSelect": item['isSelect'], "commodityType": item['commodityType']},
                                  checkboxCallback: (groupIndex, index, selected) {
                                    // print("zhe:$groupIndex, ${item['goodsId']} ,选中状态:$selected");
                                    controller.choise(item['id'], selected);
                                  },
                                ),
                            ],
                          );
                        }))
                : const NotFound(),
          ),
          Positioned(
              key: GlobalKey(debugLabel: 'Positioned'),
              bottom: MediaQuery.of(context).padding.bottom,
              child: Visibility(
                  visible: controller.showButton,
                  child: Container(
                    width: 375.w,
                    color: Colors.white,
                    padding: EdgeInsets.fromLTRB(18.w, 10.w, 18.w, 10.w),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Row(
                          children: [
                            BaseCheckBox(
                              value: controller.selectedAll,
                              onChange: (selected) {
                                controller.selectedAllItem(selected);
                              },
                            ),
                            SizedBox(width: 10.w),
                            Text("全选", style: setTextStyle(12, FontWeight.w500, Tools.fromHex("#333333")))
                          ],
                        ),
                        Row(
                          children: [
                            solidButton("收藏", radius: 30, width: 90.w, backgroundColor: Tools.fromHex("#F7CA36"), () {
                              controller.collect();
                            }),
                            SizedBox(width: 8.w),
                            solidButton("删除", radius: 30, width: 90.w, backgroundColor: Tools.fromHex("#F83F2D"), () {
                              controller.delete();
                            })
                          ],
                        )
                      ],
                    ),
                  )))
        ],
      );
    });
  }
}
